package com.ly.listener;

import com.ly.bean.EasybuyOrder;
import com.ly.bean.EasybuyOrderDetail;
import com.ly.bean.EasybuyProduct;
import com.ly.bean.EasybuyUser;
import com.ly.mapper.EasybuyProductMapper;
import com.ly.mapper.EasybuyUserMapper;
import com.ly.util.QueueNameUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @author 李岩
 * @date 2022/1/11-14:58
 * @describe
 */
@Component
@RabbitListener(queues = QueueNameUtil.FANOUT_QUEUE_NAME_USER)
public class OrderLintener {
    private final Logger logger= LoggerFactory.getLogger(OrderLintener.class);
    private OrderLintener(){
        System.out.println("进入到OrderLintener 的user");
    }

    @Autowired
    private EasybuyUserMapper userMapper;

    @RabbitHandler
    public void process(Map obj){

        try {
            logger.info("用户模块下收到的订单信息为  "+obj);
            EasybuyOrder order =(EasybuyOrder) obj.get("order");
            System.out.println("order"+order);
            EasybuyUser user = userMapper.selectByPrimaryKey(order.getUserid());
            System.out.println("user"+user);
            logger.info(user.getUsername()+"用户消费了"+order.getCost()+"元");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
